using System.Windows.Forms;
using pub.CmdUI.Cmd;
using pub.CmdUI.UI.Control;
using todo.Support;

namespace todo.Cmd.Edit.Clipboard
{
    public class CopyCmd : DefaultCmd, ICmdState
    {
        public CopyCmd()
        {
            Shortcut = new CmdShortcut(Keys.Control | Keys.C);
        }

        bool ICmdState.Enabled
        {
            get { return TodoApi.Instance.HasSelection; }
        }

        public override void Execute(IControlUI controlUi)
        {
            if (TodoApi.Instance.IsEditing() ?? false)
            {
                var text = TodoApi.Instance.GetSelectedText();
                System.Windows.Forms.Clipboard.SetText(text);
                return;
            }

            var todos = TodoApi.Instance.GetSelectedTodos();

            var clip = new TodosClip();
            clip.Todos = todos;

            var dataObject = new DataObject();
            dataObject.SetData(TodosClip.Format, clip);

            System.Windows.Forms.Clipboard.SetDataObject(dataObject, true);
        }
    }
}